﻿using System.Windows;
using LaserTag.Infrastructure;
using LaserTag.Infrastructure.RegionAdapters;
using LaserTag.Module.AForgeModule;
using LaserTag.Module.Graffiti;
using LaserTag.Module.Vision;
using LaserTag.Module.MediaKit;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Presentation.Regions;
using Microsoft.Practices.Composite.UnityExtensions;
using Microsoft.Samples.KMoore.WPFSamples.Zap;
using Transitionals.Controls;

namespace LaserTag.Shell
{
    /// <summary>
    /// The LaserTagBootstrapper is a UnityBootstrapper.  It registers
    /// any used modules and creates and runs the application's shell.
    /// </summary>
    public class LaserTagBootstrapper : UnityBootstrapper
    {
        /// <summary>
        /// Gets a catalog of all used modules within the application
        /// </summary>
        protected override IModuleCatalog GetModuleCatalog()
        {
            var catalog = new ModuleCatalog();

            /* The InfrastructureModule contains all the common
             * types used throughout the application */
            catalog.AddModule(typeof(InfrastructureModule));
            catalog.AddModule(typeof(MediaKitModule));
            catalog.AddModule(typeof(AForgeModule));
            catalog.AddModule(typeof(VisionModule));
            catalog.AddModule(typeof(GraffitiModule));
            return catalog;
        }

        protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
        {
             /* Get the default behavior factory */
            IRegionBehaviorFactory factory = base.ConfigureDefaultRegionBehaviors();

             /* Get the default mappings */
            RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();

            mappings.RegisterMapping(typeof(Window), new WindowRegionAdapter(factory));
            mappings.RegisterMapping(typeof (TransitionElement), new TransitionElementRegionAdapter(factory));
            mappings.RegisterMapping(typeof(ZapScroller), new ZapScrollerRegionAdapter(factory));
            return mappings;
        }

        /// <summary>
        /// Does any configuration with the dependency container
        /// that may be needed before the rest of the application is started.
        /// </summary>
        protected override void ConfigureContainer()
        {
            Container.RegisterType<IShellView, ShellWindow>();

            base.ConfigureContainer();
        }

        /// <summary>
        /// Creates the application's shell.  This is usually a Window
        /// </summary>
        protected override DependencyObject CreateShell()
        {
            var viewModel = Container.Resolve<ShellWindowViewModel>();
            var view = viewModel.View;

            view.Show();

            return view as DependencyObject;
        }
    }
}
